home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 684 / 684.xpi / chrome / fireftp.jar / content / js / dialogs / asciiFiles.js < prev    next >
Text File  |  2008-01-04  |  3KB  |  97 lines

  1. var gPrefAsciiFiles = new Array();
  2. var gStrbundle;
  3. var gPrefs;
  4.  
  5. // Dev note: the reason we update the gPrefAsciiFiles along with the listbox is b/c when the window is closing and you're
  6. // saving prefs the listbox has a bug (currently in Firefox 1.5) where it's like it's disposing the listbox so that you can't access it
  7.  
  8. function readPreferences() {
  9.   setTimeout(window.sizeToContent, 0);
  10.  
  11.   gStrbundle = $("strings");
  12.   var prefs  = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  13.   gPrefs     = prefs.getBranch("fireftp.");
  14.  
  15.   try {
  16.     var asciiFiles = gPrefs.getComplexValue("asciifiles", Components.interfaces.nsISupportsString).data.split(",");
  17.  
  18.     for (var x = 0; x < asciiFiles.length && asciiFiles[x] != ""; ++x) {
  19.       $('asciilist').appendItem(asciiFiles[x], asciiFiles[x]);
  20.       gPrefAsciiFiles.push(asciiFiles[x]);
  21.     }
  22.  
  23.   } catch (ex) { }
  24. }
  25.  
  26. function savePreferences() {
  27.   try {
  28.     var prefAsciiString = "";
  29.  
  30.     for (var x = 0; x < gPrefAsciiFiles.length; ++x) {
  31.       if (prefAsciiString) {
  32.         prefAsciiString += "," + gPrefAsciiFiles[x];
  33.       } else {
  34.         prefAsciiString = gPrefAsciiFiles[x];
  35.       }
  36.     }
  37.  
  38.     var sString  = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  39.     sString.data = prefAsciiString;
  40.     gPrefs.setComplexValue("asciifiles", Components.interfaces.nsISupportsString, sString);
  41.   } catch (ex) { }
  42.  
  43.   return true;
  44. }
  45.  
  46. function addType() {
  47.   var newType = window.prompt(gStrbundle.getString("addType"), "", gStrbundle.getString("asciiFiles"));
  48.  
  49.   if (!newType) {
  50.     return;
  51.   }
  52.  
  53.   newType = newType.toLowerCase();
  54.  
  55.   for (var x = 0; x < $('asciilist').getRowCount(); ++x) {
  56.     if ($('asciilist').getItemAtIndex(x).value == newType) {
  57.       return;
  58.     }
  59.   }
  60.  
  61.   for (var x = 0; x < $('asciilist').getRowCount(); ++x) {
  62.     if ($('asciilist').getItemAtIndex(x).value > newType) {
  63.       $('asciilist').insertItemAt(x, newType, newType);
  64.       $('asciilist').ensureIndexIsVisible(x);
  65.       $('asciilist').selectedIndex = x;
  66.       gPrefAsciiFiles.splice(x, 0, newType);
  67.       return;
  68.     }
  69.   }
  70.  
  71.   $('asciilist').appendItem(newType, newType);
  72.   $('asciilist').ensureIndexIsVisible($('asciilist').getRowCount() - 1);
  73.   $('asciilist').selectedIndex = $('asciilist').getRowCount() - 1;
  74.   gPrefAsciiFiles.push(newType);
  75. }
  76.  
  77. function removeType() {
  78.   if (!$('asciilist').selectedItem) {
  79.     return;
  80.   }
  81.  
  82.   var value = $('asciilist').selectedItem.value;
  83.   $('asciilist').removeItemAt($('asciilist').getIndexOfItem($('asciilist').selectedItem));
  84.  
  85.   for (var x = 0; x < gPrefAsciiFiles.length; ++x) {
  86.     if (gPrefAsciiFiles[x] == value) {
  87.       gPrefAsciiFiles.splice(x, 1);
  88.       break;
  89.     }
  90.   }
  91.  
  92.   if ($('asciilist').getRowCount()) {
  93.     $('asciilist').ensureIndexIsVisible(0);
  94.     $('asciilist').selectedIndex = 0;
  95.   }
  96. }
  97.